<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}/start/layui/css/layui.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/time_alert.css">
    <script src="{{ layui.setter.base }}/start/layui/layui.all.js"></script>
</script>
<script type="text/html" template>
    <script src="{{ layui.setter.base }}/config.js"></script>
</script>
<script type="text/html" template>
    <script src="{{ layui.setter.base }}/index.js"></script>
</script>
<script type="text/html" template>
    <script src="{{ layui.setter.base }}/lib/admin.js"></script>
</script>
<script type="text/html" template>
    <script src="{{ layui.setter.base }}/controller/api.js"></script>
</script>
<script type="text/html" template>
    <script src="{{ layui.setter.base }}/lib/view.js"></script>
</script>
<div class="layui-alert">
    <div class="layui-alert-title">时间 / 频率调整</div>
    <form class="layui-form" action="">
        <div class="alert-form-box layui-form-item">
            <label class="layui-form-label">计划开始时间:  </label>
            <div class="layui-input-block">
                <input type="text" name="tcPlanStart" required lay-verify="required" id="startTime" placeholder="" autocomplete="off" class=" alert-input layui-input">
            </div>
        </div>
        <div class="alert-form-box layui-form-item">
            <label class="layui-form-label">计划结束时间:  </label>
            <div class="layui-input-block">
                <input type="text" name="tcPlanEnd" required lay-verify="required" id="endTime" placeholder="" autocomplete="off" class="   alert-input layui-input">
            </div>
        </div>
        <div class="alert-form-box layui-form-item">
            <label class="layui-form-label">计划频率调整:  </label>
            <div class="layui-input-block">
                <select name="tcPlanFrequency" lay-filter="frequency" lay-verify="required" required id="frequency">
                    <option value=""></option>
                    <option value="H">每小时</option>
                    <option value="D">每日</option>
                    <option value="W">每周</option>
                    <option value="M">每月</option>
                </select>
            </div>
        </div>
        <div class="layui-btn-containner">
            
            <button type="button" class="btn1 alert-btn layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="submitPL">确定</button>
            <button class="btn2 alert-btn layui-btn layui-btn-radius layui-btn-primary">取消</button>
        </div>
    </form>
</div>

<script>
    ! function() {
        var $ = layui.$,
            form = layui.form,
            view = layui.view,
            laydate = layui.laydate,
            api = layui.api;   
        form.render();
        var nowTime=new Date(); 
        //开始日期-结束日期
        laydate.render({
          elem: '#startTime'
          ,type: 'datetime',
          max: 'nowTime'
        });
        laydate.render({
          elem: '#endTime'
          ,type: 'datetime',
          max: 'nowTime'
        });
        form.on('submit(submitPL)', function (data) {
            var allData = data.field;
            var opts = {
                url: api.host+api.updatePlan,
                contentType: 'application/json',
                data: JSON.stringify([allData]),
            }
            view.req(opts)
                .done((res)=>{
                    layer.msg(res.message)
                })

            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
        $('.layui-btn-containner').on('click', '.btn2', function(target) {
            var $target = $(target)
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);

        });
    }();
</script>